﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.IO;

namespace WcfService_Restful
{    
    public class Service1 : IService1
    {
        public DTO.DuLieu_DTO []GetLocation()
        {
            DAO.DuLieu_DAO data = new DAO.DuLieu_DAO();
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin: *");
            return data.GetLocation();
        }

        public DTO.QuanHuyen_DTO[] GetDistrict()
        {
            DAO.QuanHuyen_DAO data = new DAO.QuanHuyen_DAO();
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin: *");
            return data.GetData();
        }

        public DTO.Phuong_DTO[] GetWard()
        {
            DAO.Phuong_DAO data = new DAO.Phuong_DAO();
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin: *");
            return data.GetData();
        }

        public DTO.DuLieu_DTO[] SearchLocation(String MaQuan, String MaPhuong)
        {
            DAO.DuLieu_DAO data = new DAO.DuLieu_DAO();
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin: *");
            return data.SearchLocation(MaQuan, MaPhuong);
        }               

        public void InsertLocation(Stream s)
        {
            DAO.DuLieu_DAO data = new DAO.DuLieu_DAO();
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin: *");
            //WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods: GET, POST, PUT, DELETE");
            data.InsertLocation(s);           
        }

        public void UpdateLocation(Stream s)
        {
            DAO.DuLieu_DAO data = new DAO.DuLieu_DAO();
            //WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin: *");
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods: GET, POST, PUT, DELETE");
            data.UpdateLocation(s);
        }

        public void DeleteLocation(Stream s)
        {
            DAO.DuLieu_DAO data = new DAO.DuLieu_DAO();
            WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin: *");
            //WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods: GET, POST, PUT, DELETE");
            data.DeleteLocation(s);
        }
    }
}
